<?php

if (!defined('BASEPATH'))
    exit('Tidak Diperkenankan mengakses langsung');
/* Class  Model : country
 * di Buat oleh Diar PHP Generator
 * Update List untuk grid karena program generatorku lom sempurna ya hehehehehe */

class modelcountry extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function getArrayListcountry() { /* spertinya perlu lock table */
        $xBuffResul = array();
        $xStr = "SELECT " .
                "idx," .
                "country," .
                "code," .
                "idpegawai," .
                "date" .
                " FROM country   order by idx ASC ";
        $query = $this->db->query($xStr);
        $xBuffResul[0] = "~";
        foreach ($query->result() as $row) {
            $xBuffResul[$row->idx] = $row->country;
        }
        return $xBuffResul;
    }

    function getListcountry($xAwal, $xLimit, $xSearch = '') {
        if (!empty($xSearch)) {
            $xSearch = "Where country like '%" . $xSearch . "%'";
        }
        $xStr = "SELECT " .
                "idx," .
                "country," .
                "code," .
                "idpegawai," .
                "date" .
                " FROM country $xSearch order by idx DESC limit " . $xAwal . "," . $xLimit;
        $query = $this->db->query($xStr);
        return $query;
    }

    function getDetailcountry($xidx) {
        $xStr = "SELECT " .
                "idx," .
                "country," .
                "code," .
                "idpegawai," .
                "date" .
                " FROM country  WHERE idx = '" . $xidx . "'";

        $query = $this->db->query($xStr);
        $row = $query->row();
        return $row;
    }

    function getLastIndexcountry() { /* spertinya perlu lock table */
        $xStr = "SELECT " .
                "idx," .
                "country," .
                "code," .
                "idpegawai," .
                "date" .
                " FROM country order by idx DESC limit 1 ";
        $query = $this->db->query($xStr);
        $row = $query->row();
        return $row;
    }

    Function setInsertcountry($xidx, $xcountry, $xcode, $xidpegawai, $xdate) {
        $xStr = " INSERT INTO country( " .
                "idx," .
                "country," .
                "code," .
                "idpegawai," .
                "date) VALUES('" . $xidx . "','" . $xcountry . "','" . $xcode . "','" . $xidpegawai . "',now())";
        $query = $this->db->query($xStr);
        return $xidx;
    }

    Function setUpdatecountry($xidx, $xcountry, $xcode, $xidpegawai, $xdate) {
        $xStr = " UPDATE country SET " .
                "idx='" . $xidx . "'," .
                "country='" . $xcountry . "'," .
                "code='" . $xcode . "'," .
                "idpegawai='" . $xidpegawai . "'," .
                "date='" . $xdate . "' WHERE idx = '" . $xidx . "'";
        $query = $this->db->query($xStr);
        return $xidx;
    }

    function setDeletecountry($xidx) {
        $xStr = " DELETE FROM country WHERE country.idx = '" . $xidx . "'";

        $query = $this->db->query($xStr);
        $this->setInsertLogDeletecountry($xidx);
    }

    function setInsertLogDeletecountry($xidx) {
        $xidpegawai = $this->session->userdata('idpegawai');
        $xStr = "insert into logdelrecord(idxhapus,nmtable,tgllog,ideksekusi) values($xidx,'country',now(),$xidpegawai)";
        $query = $this->db->query($xStr);
    }

}

?>